package fmse.uaic.k.configuration_abstraction.visitors;

import java.util.ArrayList;
import java.util.List;

import fmse.uaic.k.configuration_abstraction.abstract_classes.KAbstractNode;
import fmse.uaic.k.configuration_abstraction.abstract_visitor.KAbstractNodeVisitor;
import fmse.uaic.k.configuration_abstraction.data_structures.ConfigurationKTree;

/**
 * This class checks if a node in a rule is defined in a given configuration.
 * 
 * @author andreiarusoaie
 * 
 */
public class CheckLabelDeclarationVisitor extends KAbstractNodeVisitor {

	ConfigurationKTree tree;
	List<KAbstractNode> undefined;
	SearchByLabelVisitor labelsVisitor;

	public CheckLabelDeclarationVisitor(ConfigurationKTree tree) {
		super();
		this.tree = tree;
		this.undefined = new ArrayList<KAbstractNode>();
		this.labelsVisitor = new SearchByLabelVisitor();
	}

	@Override
	public void visit(KAbstractNode abstractNode) {
		labelsVisitor.setLabel(abstractNode.getLabel());
		labelsVisitor.getNodes().clear();
		tree.dfs(labelsVisitor);
		if (labelsVisitor.getNodes().size() == 0)
			undefined.add(abstractNode);
	}

	public ConfigurationKTree getTree() {
		return tree;
	}

	public void setTree(ConfigurationKTree tree) {
		this.tree = tree;
	}

	public List<KAbstractNode> getUndefined() {
		return undefined;
	}

	public void setUndefined(List<KAbstractNode> undefined) {
		this.undefined = undefined;
	}

}
